package com.youlai.boot.system.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.common.result.ResultCode;
import com.youlai.boot.system.model.qb.Answers;
import com.youlai.boot.system.service.AnswersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/answers")
public class AnswersController {
    @Autowired
    private AnswersService answersService;
    @PostMapping("/save")
    public Result<?> saveAnswers(@RequestBody List<Answers> answers){
        return Result.judge(answersService.saveAnswers(answers),"新增成功","新增失败");
    }

    @GetMapping("/all")
    public Result<List<Answers>> getAllAnswers(){
        List<Answers> answers = answersService.getAllAnswers();
        Result<List<Answers>> result;
        if (!answers.isEmpty()){
            result = Result.success(answers);
            result.setMessage("查询成功");
            result.setCode(ResultCode.SUCCESS.getCode());
        }else {
            result = Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR);
            result.setMessage("查询失败，请重新查询");
        }
        return result;
    }
}
